package com.wink_172

import android.content.ContentProvider
import android.content.ContentValues
import android.content.UriMatcher
import android.database.Cursor
import android.net.Uri

/**
 *创建ContentProvider
 *p334
 */
class CustomerProvider : ContentProvider() {

    private val table1Dir = 0
    private val table1Item = 1
    private val table2Dir = 2
    private val table2Item = 3

    private val uriMatcher = UriMatcher(UriMatcher.NO_MATCH)

    init {
        uriMatcher.addURI("com.sunrise.shopping.provider", "table1", table1Dir)
        uriMatcher.addURI("com.sunrise.shopping.provider", "table1/#", table1Item)
        uriMatcher.addURI("com.sunrise.shopping.provider", "table2", table2Dir)
        uriMatcher.addURI("com.sunrise.shopping.provider", "table2/#", table2Item)

    }

    override fun onCreate(): Boolean {
        TODO("Not yet implemented")
    }

    override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? {
        when (uriMatcher.match(uri)) {

            table1Dir -> {
                //查询table1表中所有数据
            }

            table1Item -> {
                //查询table1表中单条数据
            }

            table2Dir -> {
                //查询table2表中所有数据
            }

            table2Item -> {
                //查询table2表中单条数据
            }
        }

        return null   //注意这里需要返回Cursor
    }

    /**
     *p335
     * */
    override fun getType(uri: Uri): String? {
        when (uriMatcher.match(uri)) {
            table1Dir ->return "vnd.android.cursor.dir/vnd.com.sunrise.shopping.provider.table1"    //dir
            table1Item -> return "vnd.android.cursor.item/vnd.com.sunrise.shopping.provider.table1"  //item
            table2Dir -> return "vnd.android.cursor.dir/vnd.com.sunrise.shopping.provider.table2"
            table2Item ->return "vnd.android.cursor.item/vnd.com.sunrise.shopping.provider.table2"
            else -> return null
        }

    }

    override fun insert(uri: Uri, values: ContentValues?): Uri? {
        TODO("Not yet implemented")
    }

    override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
        TODO("Not yet implemented")
    }

    override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int {
        TODO("Not yet implemented")
    }
}